package com.xframe.domain.e3sp.bu.sale;

import com.xframe.domain.BaseModel;
import com.xframe.domain.e3sp.maindata.domestic.Dealer;
import com.xframe.domain.sys.SysValueDetail;
import com.xframe.xdal.core.annotation.*;
import com.xframe.xdal.core.constant.AutoFillType;
import lombok.Data;
import lombok.experimental.Accessors;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * @Description: 国内订单
 * @ClassName: com.xframe.domain.e3sp.bu.sale.Order
 * @Author: xufeng
 * @CreateTime: 2024/3/10
 *
 **/
@Data
@Accessors(chain=true)
@XTable(value = "bu_t01_order", label = "国内订单",dataSourceCode = "warehouse")
@XBelongsTo(typeName = "com.xframe.domain.e3sp.maindata.domestic.Dealer",foreignKey = "dealerId",
        targetKey = "dealerId",as = "refDealer")
@XBelongsTo(typeName = "com.xframe.domain.sys.SysValueDetail",foreignKey = "transportation",
        targetKey = "val",refTableAddString = "val_code = '1003'",as = "refTransportation")
@XHasMany(typeName = "com.xframe.domain.e3sp.bu.sale.OrderDetail",foreignKey = "orderId", targetKey = "orderId",as = "detailList")
public class Order extends BaseModel {
    /**
     * 国内订单ID
     */
    @AutoFill(AutoFillType.Snowflake)
    @XColumn(name = "order_id", primaryKeyFlag = true,desc = "国内订单ID")
    private Long orderId;

    /**
     * 国内活动包ID
     */
    @XColumn(name = "activity_id",desc = "国内活动包ID",nullFlag = true)
    private Long activityId;

    /**
     * 经销商ID
     */
    @XColumn(name = "dealer_id",desc = "经销商ID",nullFlag = true)
    private Long dealerId;

    /**
     * 零售客户ID
     */
    @XColumn(name = "customers_id",desc = "零售客户ID",nullFlag = true)
    private Long customersId;

    /**
     * 订单号
     */
    @XColumn(name = "order_no",desc = "订单号",uniqueFlag = true,length = 50)
    private String orderNo;

    /**
     * 订单类型
     * 0 = 普通订单 1 = 紧急订单 2=直送订单
     * 3=客户订单 4=日产订单 5=三包订单 6=活动订单 7=特殊订单
     */
    @XColumn(name = "order_type",desc = "订单类型")
    private Integer orderType;

    /**
     * 订单日期
     */
    @XColumn(name = "orderdate",desc = "订单日期")
    private Date orderDate;

    /**
     * 总金额
     */
    @XColumn(name = "total_amount",desc = "总金额")
    private BigDecimal totalAmount;

    /**
     * 现款金额
     */
    @XColumn(name = "cash_amount",desc = "现款金额")
    private BigDecimal cashAmount;

    /**
     * 折扣金额
     */
    @XColumn(name = "discount_amount",desc = "折扣金额")
    private BigDecimal discountAmount;

    /**
     * 期望到货日期
     */
    @XColumn(name = "hope_date",desc = "期望到货日期")
    private Date hopeDate;

    /**
     * 技术报告编号
     */
    @XColumn(name = "report_no",desc = "技术报告编号",nullFlag = true,length = 50)
    private String reportNo;

    /**
     * 经办人
     */
    @XColumn(name = "attn",desc = "经办人",nullFlag = true,length = 50)
    private String attn;

    /**
     * 收货地址
     */
    @XColumn(name = "delivery_address",desc = "收货地址",length = 200)
    private String deliveryAddress;

    /**
     * 备注
     */
    @XColumn(name = "remark",desc = "备注",nullFlag = true,length = 500)
    private String remark;


    /**
     * 状态
     * 1=新建 2=提交 3=审核通过 FP=分配中 OK= 分配完成 9 = 作废 CK = 出库 99 = 驳回
     */
    @XColumn(name = "status",desc = "状态",length = 20)
    private String status;

    /**
     * 运输方式 值列表类型 = 1003
     */
    @XColumn(name = "transportation",desc = "运输方式",nullFlag = true,length = 20)
    private String transportation;


    /**
     * 订单创建方式
     * 0 = 经销商创建 1 = 总部创建
     */
    @AutoFill(defVal = "0")
    @XColumn(name = "c_mode",desc = "订单创建方式")
    private Integer cMode;

    /**
     * 创建的经销商ID
     */
    @AutoFill(defVal = "0")
    @XColumn(name = "cid",desc = "创建的经销商ID",nullFlag = true)
    private Long cid;

    /**
     * 订单销退单ID
     */
    @XColumn(name = "return_id",desc = "订单销退单ID",nullFlag = true)
    private Long returnId;



    /**
     * 国内经销商
     */
    private Dealer refDealer;

    /**
     * 运输方式
     */
    private SysValueDetail refTransportation;

    /**
     * 明细数据
     */
    private List<OrderDetail> detailList;


    public String getOrderTypePre(){
        switch (this.orderType){
            case 0:
                return "GO";
            case 1:
                return "EO";
            case 2:
                return "ZS";
            case 3:
                return "KH";
            case 4:
                return "RC";
            case 5:
                return "SB";
            case 6:
                return "HD";
            case 7:
                return "TS";
            default:
                return "GO";
        }
    }
}
